<?php
namespace Home\Controller;
use Think\Controller;
use Think\TopClient;
class IndexController extends Controller {
 //计算范围，可以做搜索用户  log 经度 lat纬度
    public function index(){
        $this->display('erweima');
    }
       public function index2(){     
        $num=I('num');
        $maxnum=M('num')->max('num');
        $starNum=$maxnum+1;
        if(empty($starNum)){
            $starNum=1;
        }
        $address='Uploads/'.date('Y-m-d').'/Er/'.$starNum.'-'.($maxnum+$num).'/';
        makeDir($address);
        $max=$maxnum+$num;
       for ($i=$starNum; $i <=$max; $i++) { 
        Vendor('phpqrcode.phpqrcode');
        //生成二维码图片
        $object = new \QRcode();
        $can1=strrev(md5(sha1(md5(sha1(sha1(sha1(md5(md5(md5(sha1(sha1(md5(md5($i))))))))))))));
        $can=$this->generate_password(2).$can1.$this->generate_password(1);
        $url='http://lose.cwlyz.cn/index.php/Home/Index/index/idinfo/'.$can;//网址或者是文本内容
        $level=3;
        $size=4;
        $errorCorrectionLevel =intval($level) ;//容错级别
        $matrixPointSize = intval($size);//生成图片大小
        $fieldname=$i.'.jpg';
        $info=$object->png($url, $fieldname, $errorCorrectionLevel, $matrixPointSize, 2,$saveandprint); 
        $image = new \Think\Image(); 
        $image->open('./'.$i.'.jpg')->water('./qq2.png',\Think\Image::IMAGE_WATER_CENTER,100)->save('Uploads/'.date('Y-m-d').'/Er/'.$starNum.'-'.$max.'/'.$i.'.jpg'); 
         unlink('./'.$i.'.jpg');
         $a_num['num']=$i;
         $maxnum=M('num')->add($a_num);
       }
        if($maxnum){
          $this->ajaxReturn(100);
        }else{
          $this->ajaxReturn(101);  
        }
    }
     public  function generate_password( $length ) { 
            // 密码字符集，可任意添加你需要的字符 
            $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 
            $password =''; 
            for ( $i = 0; $i < $length; $i++ ) 
            { 
            // 这里提供两种字符获取方式 
            // 第一种是使用 substr 截取$chars中的任意一位字符； 
            // 第二种是取字符数组 $chars 的任意元素 
            // $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1); 
            $password .= $chars[ mt_rand(0, strlen($chars) - 1) ]; 
            } 
            return $password; 
            }

       public function index1(){
       for ($i=0; $i < 10; $i++) { 
        Vendor('phpqrcode.phpqrcode');
        //生成二维码图片
        $object = new \QRcode();
        $url='http://www.baidu'.$i.'.com/';//网址或者是文本内容
        $level=3;
        $size=4;
        $errorCorrectionLevel =intval($level) ;//容错级别
        $matrixPointSize = intval($size);//生成图片大小
        $saveandprint='./';
        $fieldname=$i.'.jpg';
        $info=$object->png($url, $fieldname, $errorCorrectionLevel, $matrixPointSize, 2,$saveandprint); 
       }
    }
//通过城市ip  获取地址
     public function cityip(){
            $lng=I('lng');
            $lat=I('lat');
            $http="http://api.map.baidu.com/geocoder/v2/?callback=''&location=".$lng.",".$lat."&output=json&pois=1&ak=dRUrTiX4xnubXnGkqGrBU8jSfNBtXP6n";
            $ch = curl_init ();
            curl_setopt ( $ch, CURLOPT_URL, $http );
            curl_setopt ( $ch, CURLOPT_POST, 1 );
            curl_setopt ( $ch, CURLOPT_HEADER, 0 );
            curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
            curl_setopt ( $ch, CURLOPT_POSTFIELDS,$array);
            $return = curl_exec ( $ch );
            curl_close ( $ch );
            $info= json_decode($return);

            dump($info->result->addressComponent->country);
            dump($info->result->addressComponent->province);
            dump($info->result->addressComponent->city);
            dump($info->result->addressComponent->district);
            dump($info->result->addressComponent->street);
            dump($info->result->addressComponent->direction);
     }
  }
 

